/**
 * Copyright (C), 2001-2023, www.bosssof.com.cn
 * FileName: UserApi
 * Author: Administrator
 * Date: 2023-03-30 16:00:07
 * Description:
 * <p>
 * History:
 * <author> Administrator
 * <time> 2023-03-30 16:00:07
 * <version> 1.0.0
 * <desc> 版本描述
 */
package com.bosssoft.g1.api;

import com.bosssoft.g1.common.data.dto.IdVersion;
import com.bosssoft.g1.common.data.vo.CommonResponse;
import com.bosssoft.g1.dto.PageDTO;
import com.bosssoft.g1.dto.ResourceDTO;
import com.bosssoft.g1.dto.RoleDTO;
import com.bosssoft.g1.dto.UserDTO;
import com.bosssoft.g1.entity.Node;
import com.bosssoft.g1.entity.Resource;
import com.bosssoft.g1.vo.IdNameVO;
import com.bosssoft.g1.vo.ResourceVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @ClassName: ResourceApi
 * @Description: 有用配合前端演示资源增删改查的demo
 * @Author: Administrator
 * @Date: 2023-03-30 16:00
 **/

@CrossOrigin
@Api(tags = "资源管理 ", value = "/v1/resource")
@RequestMapping("/v1/resource")
@Validated
public interface ResourceApi {
    /**
     * 开始时获取所有资源信息
     * @return: CommonResponse
     */
    @ApiOperation( value = "所有资源信息")
    @GetMapping( "/all")
    @ResponseBody
    CommonResponse<PageInfo<ResourceDTO>> getAllRes(PageDTO pageDTO);

    /**
     * 开始时获取该租户的所有子系统
     * @return: CommonResponse
     */
    @ApiOperation( value = "获取子系统")
    @GetMapping( "/allSubSystem")
    @ResponseBody
    CommonResponse<List<IdNameVO>> getAllSubSystem();

    /**
     * 界面调用接口增加资源
     *
     * @param
     * @return true成功 false失败
     */
    @ApiOperation(value = "增加资源", notes = "界面增加资源")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "请求执行没有成功但是发生异常")})
    @GetMapping("/search")
    CommonResponse<PageInfo<ResourceVO>> resourceName(@RequestParam(defaultValue = "1") String name, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize);

    /**
     * 批量删除资源？
     *
     * @param id 记录id
     * @return true 成功 false失败
     */
    @ApiOperation(value = "批量删除资源通过id？", notes = "通过id删除资源")
    @ApiImplicitParam(name = "id", required = true, dataType = "Long", paramType = "path")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @GetMapping("/resourceTree")
    CommonResponse<PageInfo<ResourceVO>> resourceTree(@RequestParam(defaultValue = "1") Long id, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize);

    /**
     * 增加资源
     *
     * @param resourceDTO      资源DTO
     * @return true 成功 false失败
     */
    @ApiOperation(value = "新增资源", response = Boolean.class, notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "version", required = true, dataType = "Long", paramType = "query")})
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @PostMapping("/addResource")
    CommonResponse<Boolean> addResource(@Valid @RequestBody @ApiParam(value = "资源数据", required = true) ResourceDTO resourceDTO);

    /**
     * 通过 id 查询资源
     *
     * @param id 当前行id
     * @return 资源数据
     */
    @ApiOperation(value = "根据id获取资源接口", notes = "用于编辑和查看的时候获取资源")
    @ApiImplicitParam(name = "id", value = "主键值", required = true, dataType = "Long", paramType = "path")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功,非0码则代表失败"),})
    @GetMapping("/resource/{id}")
    CommonResponse<ResourceVO> findById(@PathVariable @NotNull Long id);

    /**
     * 资源修改结果保存
     *
     * @param resourceDTO 资源信息包含 id
     * @return true成功 false失败
     */
    @ApiOperation(value = "更新资源信息", notes = "修改界面保存调用该方法")
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @PutMapping("/updateResource")
    CommonResponse<Boolean> updateResource(@NotNull @Valid @RequestBody @ApiParam ResourceDTO resourceDTO);

    /**
     * 删除单个资源
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除单个资源通过id", response = Boolean.class, notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "idVersions", required = true, dataType = "IdVersion", paramType = "body")})
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @DeleteMapping("/deleteResource")
    CommonResponse<Boolean> deleteResource(@RequestParam Long id);

    /**
     * 批量删除资源
     * @param resourceDTOS
     * @return
     */
    @ApiOperation("批量删除资源")
    @DeleteMapping("/delete")
    @ResponseBody
    CommonResponse<Boolean> batchDeleteResource(@NotEmpty @RequestBody List<ResourceDTO> resourceDTOS);

    /**
     * 显示资源树
     * @param id
     * @return
     */
    @ApiOperation(value = "显示资源树", response = Boolean.class, notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "idVersions", required = true, dataType = "IdVersion", paramType = "body")})
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @GetMapping("/queryResourceByTenantId")
    CommonResponse<List<Node>> queryResourceByTenantId(@RequestParam(value = "id") @NotNull Long id);

    /**
     * 增加资源框显示父亲节点
     * @param id
     * @return
     */
    @ApiOperation(value = "增加资源框显示父亲节点", response = Boolean.class, notes = "notes说明")
    @ApiImplicitParams({@ApiImplicitParam(name = "idVersions", required = true, dataType = "IdVersion", paramType = "body")})
    @ApiResponses({@ApiResponse(code = 0, message = "请求成功"), @ApiResponse(code = -1, message = "没有更新记录,非0码则代表失败")})
    @GetMapping("/queryResourceBySubsId")
    CommonResponse<List<Node>> queryResourceBySusId(@RequestParam(value = "id") @NotNull Long id);
}

